package com.imcode;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * 一次读取一个字节数组
 */
public class InputStreamDemo02 {
    public static void main(String[] args) throws IOException {
        //1.创建一个 InputStream的子类对象，FileInputStream 按字节读取文件
        InputStream in = new FileInputStream(new File("D:\\test.txt"));
        //2.创建一个字节数组
        byte[] bytes = new byte[10];//1KB 数组的长度用计算机存储单位的整数倍

        /*
        System.out.println(in.read(bytes));//3
        System.out.println(in.read(bytes));//3
        System.out.println(in.read(bytes));//1
        System.out.println(in.read(bytes));// 返回-1表示读取结束*/

        /*
        in.read(bytes);
        for(int i=0;i<bytes.length;i++){
            System.out.println(bytes[i]);
        }*/

        /*
        int len = 0;
        while ((len = in.read(bytes)) != -1) {
            for(int i=0;i<len;i++){
                System.out.println(bytes[i]);
            }
            System.out.println("---------------");
        }*/

        int len = bytes.length;
        while ((len = in.read(bytes,0,len)) != -1) {
            for(int i=0;i<bytes.length;i++){
                System.out.println(bytes[i]);
            }
            System.out.println("---------------");
        }
    }
}
